package com.lk.web.old;

import com.alibaba.fastjson.JSON;
import com.lk.pojo.Brand;
import com.lk.service.BrandService;
import com.lk.service.impl.BrandServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;

//@WebServlet("/addServlet")
public class AddServlet extends HttpServlet {

    private BrandService brandService=new BrandServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收以JSON格式发送过来的数据
        BufferedReader br = request.getReader();
        String params = br.readLine(); //JSON字符串

        //转为brand对象
        Brand brand = JSON.parseObject(params, Brand.class);

        //调用service添加
        brandService.add(brand);

        //响应成功的表示
        response.getWriter().write("success");

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doGet(request,response);
    }
}
